package com.hdf.etdemo.view.listview.adapter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.hdf.etdemo.R;
import com.nostra13.universalimageloader.core.ImageLoader;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ListViewAdapter  extends BaseAdapter{
	private LayoutInflater layoutInflater;
	private Context context;
	private List<Map<String,Object>> appLists;
	public ListViewAdapter(Context cxt,List<Map<String,Object>> appLists){
		this.context=cxt;
		this.appLists=appLists;
		layoutInflater = LayoutInflater.from(context);
		appLists=new ArrayList<Map<String,Object>>();
	}
	
	@Override
	public int getCount() {
		return appLists.size();
	}

	@Override
	public Object getItem(int position) {
		return appLists.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = layoutInflater.inflate(R.layout.listview_item, null);
			/**照片 */
			holder.image = (ImageView) convertView.findViewById(R.id.item_imge);
			;
			/**标题*/
			holder.title = (TextView) convertView.findViewById(R.id.item_text);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
			holder.title.setText(appLists.get(position).get("name").toString());
		ImageLoader.getInstance().displayImage(appLists.get(position).get("imgurl").toString(), holder.image);
		return convertView;
	}
	
	public void setAppList(List<Map<String,Object>> inforL) {
		this.appLists = inforL;
	}
	
	

	public class ViewHolder {
		/** 头像 */
		private ImageView image;
		/** 標題 */
		private TextView title;
		/** 内容 */
		private TextView content;
	}

}
